package com.ymttest.business.service.YMTTrading;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.google.common.collect.Lists;
import com.ymatou.iapi.optrade.parameter.enums.BondedAreaEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.optrade.parameter.vo.BizVo;
import com.ymatou.iapi.optrade.parameter.vo.CouponVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderGroupVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderItemVo;
import com.ymatou.iapi.optrade.parameter.vo.OrderVo;
import com.ymatou.iapi.optrade.parameter.vo.ThirdPartyPromotionVo;
import com.ymatou.iapi.optrade.parameter.vo.UbuyUserVo;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

public class TradingPlaceOrderCallService {
	
	private static Long sellerId = Long.valueOf(EnvSetup.getData("autotest_seller1"));
	private static String sellerName = String.valueOf(EnvSetup.getData("autotest_sellerName1"));
	
	/**
	 * 根据物流类型 下分期乐订单
	 * 
	 * @param logisticsType
	 *            物流类型
	 * @return
	 */
	public static TradingServiceResp placeFenqileOrder(LogisticsTypeEnum logisticsType) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		orderVo.withOrderType(4).withLogisticsType(logisticsType);

		if (logisticsType.compareTo(LogisticsTypeEnum.BondedDelivery) == 0)
			orderItemVo.withBondedArea(BondedAreaEnum.ShenZhen);
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}
	
	/**
	 * 根据满减包邮类型 下单
	 * 
	 * @param fullReductionFreeFreight
	 *            是否满减包邮
	 * @return
	 */
	public static TradingServiceResp placeOrderWithFullReductionFreeFreight(Boolean fullReductionFreeFreight) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		orderItemVo.setFullReductionFreeFreight(fullReductionFreeFreight);
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}

	/**
	 * 根据物流类型 下单
	 * 
	 * @param logisticsType
	 *            物流类型
	 * @return
	 */
	public static TradingServiceResp placeOrderWithLogisticsType(LogisticsTypeEnum logisticsType) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		if (logisticsType.compareTo(LogisticsTypeEnum.BondedDelivery) == 0)
			orderItemVo.setBondedArea(BondedAreaEnum.ShenZhen);
		
		orderVo.withLogisticsType(logisticsType).withLogisticsAging(20);
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}

	/**
	 * 根据物流类型和拼邮方式下单
	 * @param logisticsType
	 * @param packageDeliveryType
	 * @return
	 */
	public static TradingServiceResp placeOrderWithLogisticsTypeAndPackageDeliveryType(
			LogisticsTypeEnum logisticsType, Integer packageDeliveryType) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		if (logisticsType.compareTo(LogisticsTypeEnum.BondedDelivery) == 0)
			orderItemVo.setBondedArea(BondedAreaEnum.ShenZhen);
		
		orderVo.withLogisticsType(logisticsType).withPackageDeliveryType(packageDeliveryType);
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}

	/**
	 * 根据拼邮方式下单
	 * @param packageDeliveryType
	 * @return
	 */
	public static TradingServiceResp placeOrderWithPackageDeliveryType(Integer packageDeliveryType) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		orderVo.withPackageDeliveryType(packageDeliveryType);
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}
	
	/**
	 * 根据ubuy信息 下单
	 * 
	 * @param ubuyUserVo
	 *            ubuy信息
	 * @return
	 */
	public static TradingServiceResp placeOrderWithUbuy(UbuyUserVo ubuyUserVo) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));
		
		placeorderBean.setUbuyUserVo(ubuyUserVo);

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}
	
	/**
	 * 下一个第三方优惠订单
	 * @return
	 */
	public static TradingServiceResp placeOrderWithThirdPartyPromotion() {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		ThirdPartyPromotionVo thirdPartyPromotionVo = new ThirdPartyPromotionVo();

		thirdPartyPromotionVo.setThirdPartyName(TestDataManager.randomStr(10)
				+ "thirdPartyName");
		
		thirdPartyPromotionVo.setThirdPartyPromoter(TestDataManager
				.randomStr(10) + "thirdPartyPromoter");
		thirdPartyPromotionVo.setThirdPartySubPlatform(TestDataManager
				.randomStr(10) + "thirdPartySubPlatform");
		thirdPartyPromotionVo.setOuterParam(TestDataManager.randomStr(10)
				+ "outerParam");

		placeorderBean.setThirdPartyPromotion(thirdPartyPromotionVo);
		placeorderBean.setOuterPromotionId(thirdPartyPromotionVo
				.getThirdPartyName());

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}
	
	/**
	 * 根据graphicProduct信息 下单
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrderWithGraphicProduct(
			Boolean graphicProduct) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		orderItemVo.setGraphicProduct(graphicProduct);
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}
	
	/**
	 * 根据luxury信息 下单
	 * 
	 * @return
	 */
	public static TradingServiceResp placeOrderWithLuxury(
			Boolean luxury) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		orderItemVo.setLuxury(luxury);
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}
	
	
	/**
	 * 根据luxury信息 下单
	 * 
	 * @return
	 * @throws Exception 
	 */
	public static TradingServiceResp placeOrderWithAuthenticateRuleId(
			Long authenticateRuleId) throws Exception {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		orderItemVo.setLuxury(true);
		orderItemVo.setAuthenticateRuleId(authenticateRuleId);
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);
		

//		PlaceOrderReq placeOrderReq = TradingCallService.buildDemoReq(false);
//
//		OrderVo orderVo = placeOrderReq.getOrderGroups().get(0).getOrders()
//				.get(0);
//		OrderItemVo orderItemVo = orderVo.getOrderItems().get(0);
//
//		//鉴别物流费
//		orderVo.setAuthenticateFreight(new BigDecimal(8));
//		//鉴别物流费类型承担方（1、买手 2、买家）
//		orderVo.setAuthenticateFreightType(AuthenticateFreightTypeEnum.SELLER
//				.getCode());
//
//		//鉴定标记
//		orderItemVo.setAuthenticateFlag(true);
//		//鉴别费（单个）
//		orderItemVo.setAuthenticateFee(new BigDecimal(11));
//		//鉴别费承担方
//		orderItemVo.setAuthenticateFeeType(AuthenticateFeeTypeEnum.SELLER
//				.getCode());
//        //是否奢侈品
//		orderItemVo.setLuxury(true);
//		//鉴别规则ID
//		orderItemVo.setAuthenticateRuleId(1L);
//
//		//return TradingCallService.callPlaceOrderService(placeOrderReq);
//		
//		Logger.comment("############################下单-支付-卖家接单-鉴定中心发货-确认收货");
//		//下单-支付-卖家接单-鉴定中心发货-确认收货
//        TradingServiceResp placeOrderResp = TradingCallService.callPlaceOrderService(placeOrderReq);
//
//        String payType = "13";
//
//        // 支付收单
//        Long thirdTradingId = TradingCallService.payOrder(placeOrderResp.getUserId(), BigDecimal.ZERO,
//                        placeOrderResp.getTradingId(), payType);
//
//        // 支付网关支付回调交易(付款)
//        PayGateWayCallService.notifyCall(payType, String.valueOf(thirdTradingId),
//                        placeOrderResp.getPayableAmount().toString(), placeOrderResp.getUserId());
//
//        Thread.sleep(6000);
//
////        // 卖家接单
//        TradingCallService.sellerAcceptOrder(sellerId, placeOrderResp.getOrderList().get(0).getOrderId());
//        TradingSyncService.getSyncResult(placeOrderResp.getOrderList().get(0).getOrderId());
//        Thread.sleep(1000);
//        // 拼邮国际段发货-authenticatePackage  是有鉴别包裹的物流信息
//        TradingCallService.delivery(sellerId, placeOrderResp.getOrderList().get(0).getOrderId(), LogisticsTypeEnum.OVERSEAS_DELIVERY, "Y013", 1, true);
//        TradingSyncService.getSyncResult(placeOrderResp.getOrderList().get(0).getOrderId());
//        Thread.sleep(1000);
//        // 鉴定中心发货
//        TradingCallService.authenticateDelivery(sellerId, placeOrderResp.getOrderList().get(0).getOrderId());
//        TradingSyncService.getSyncResult(placeOrderResp.getOrderList().get(0).getOrderId());
//        Thread.sleep(1000);
//        // 确认收货
//        TradingCallService.confirmReceive(placeOrderResp.getUserId(),
//                        placeOrderResp.getOrderList().get(0).getOrderId());
//        
//
//        return placeOrderResp;
//		//return TradingCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 根据返点金额下单
	 * @param rebatePaidAmount
	 * @return
	 */
	public static TradingServiceResp placeOrderWithRebatePaidAmount(BigDecimal rebatePaidAmount) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));
		
		placeorderBean.setRebatePaidAmount(rebatePaidAmount);

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}
	
	/**
	 * 根据物流类型、买手Id、买手名称 下单
	 * 
	 * @param logisticsType
	 *            物流类型
	 * @param sellerId
	 *            买手id
	 * @param sellerName
	 *            买手名称
	 * @return
	 */
	public static TradingServiceResp placeOrder(
			LogisticsTypeEnum logisticsType, long sellerId, String sellerName) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		orderVo.withLogisticsType(logisticsType);
		
		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}
	
	/**
	 * 根据物流类型、买手Id、买手名称 下官方物流订单
	 * 
	 * @param logisticsType
	 *            物流类型
	 * @param sellerId
	 *            买手id
	 * @param sellerName
	 *            买手名称
	 * @return
	 */
	public static TradingServiceResp placeOfficialLogisticsOrder(
			LogisticsTypeEnum logisticsType, long sellerId, String sellerName) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();

		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		orderVo.withLogisticsType(logisticsType).withOfficialLogistics(true);

		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}
	
	/**
	 * 根据物流类型 下官方物流订单
	 * @param logisticsType
	 * @return
	 */
	public static TradingServiceResp placeOfficialLogisticsOrderWithLogisticsType(
			LogisticsTypeEnum logisticsType) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();

		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		orderVo.withLogisticsType(logisticsType).withOfficialLogistics(true);

		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeorderBean);

	}

	/**
	 * 根据userId 下单
	 * 
	 * @param userId
	 *            买家id
	 * @return
	 */
	public static TradingServiceResp placeOrderWithUserId(int userId) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();

		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();

		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo));
		
		placeorderBean.withUserId((long)userId);

		return TradingCallService.callPlaceOrderService(placeorderBean);

	}
	
	/**
	 * 创建一个带优惠券的订单
	 * @return
	 */
	public static TradingServiceResp placeOrderWithCoupon() {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();
		long userId = placeOrderReq.getUserId();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();

		// 创建一个普通商品
		TradingProductVo product = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(
				product.getProductId(), product.getCatalogId());

		orderItemVo.setBuyDailyLimit(true);
		
		orderVo.setOrderItems(Arrays.asList(orderItemVo));
		orderGroupVo.setOrders(Arrays.asList(orderVo));

		// 平台券
		placeOrderReq.setYmatouCoupon(TradingAllPromotion.createYMTCouponVo(
				userId, BigDecimal.TEN, BigDecimal.ONE));
		// 商家券
		CouponVo sellerCoupon = TradingAllPromotion.createSellerCouponVo(
				userId, sellerId, new BigDecimal(30), BigDecimal.TEN);

		orderGroupVo.setSellerCoupon(sellerCoupon);
		
		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

		return TradingCallService.callPlaceOrderService(placeOrderReq);

	}
	
	/**
	 * 1个买手,多商品,生成单个订单
	 * 
	 * @param isUserCoupon
	 *            是否使用优惠券（同时使用平台券，商家券）
	 * @param virtualProduct
	 *            是否虚拟商品
	 * @return
	 */
	public static TradingServiceResp placeOrderWithTwoProcutInOneOrder(boolean isUserCoupon,
			boolean virtualProduct) {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();
		long userId = placeOrderReq.getUserId();

		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo = TradingCallService.createOrderVo();

		// 创建第一个普通商品
		TradingProductVo product1 = TradingProductVo.createPro(sellerId,
				sellerName, 100);

		OrderItemVo orderItemVo1 = TradingCallService.createOrderItemVo(
				product1.getProductId(), product1.getCatalogId());
		
		// 创建第二个普通商品
		TradingProductVo productVo2 = TradingProductVo.createPro(sellerId, sellerName, 10);

		OrderItemVo orderItemVo2 = TradingCallService.createOrderItemVo(
				productVo2.getProductId(), productVo2.getCatalogId());
		
		// 虚拟商品
		if (virtualProduct)
			orderVo.withLogisticsType(LogisticsTypeEnum.AutoDelivery);

		orderVo.setOrderItems(Arrays.asList(orderItemVo1, orderItemVo2));
		orderGroupVo.setOrders(Arrays.asList(orderVo));
		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

		if (isUserCoupon) {

			CouponVo sellerCoupon1 = TradingAllPromotion.createSellerCouponVo(
					userId, sellerId, new BigDecimal(30), BigDecimal.TEN);

			orderGroupVo.setSellerCoupon(sellerCoupon1);

			CouponVo ymatouCoupon = TradingAllPromotion.createYMTCouponVo(
					userId, new BigDecimal(60), BigDecimal.TEN);
			placeOrderReq.setYmatouCoupon(ymatouCoupon);
		}
		
		return TradingCallService.callPlaceOrderService(placeOrderReq);
	}

	/**
	 * 
	 * @param isUserCoupon 是否使用优惠券（同时使用平台券，商家券）
	 * @param payDeductAmount 支付立减金额
	 * @param userId 买家id
	 * @param logisticsType 物流类型
	 * @return
	 */
	public static TradingServiceResp placeOrderWithThreeProcutInTwoOrder(boolean isUserCoupon,
			BigDecimal payDeductAmount, long userId, LogisticsTypeEnum logisticsType) {

		PlaceOrderReq placeOrderReq = TradingCallService
				.buildStandPlaceOrderReq();
		
		OrderGroupVo orderGroupVo = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);
		OrderVo orderVo1 = TradingCallService.createOrderVo();

		// 创建三个普通商品
		TradingProductVo productVo1 = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		TradingProductVo productVo2 = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		TradingProductVo productVo3 = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		
		OrderItemVo orderItemVo1 = TradingCallService.createOrderItemVo(
				productVo1.getProductId(), productVo1.getCatalogId());
		OrderItemVo orderItemVo2 = TradingCallService.createOrderItemVo(
				productVo2.getProductId(), productVo1.getCatalogId());
		OrderItemVo orderItemVo3 = TradingCallService.createOrderItemVo(
				productVo3.getProductId(), productVo1.getCatalogId());

		orderVo1.setOrderItems(Arrays.asList(orderItemVo1, orderItemVo2));
		orderVo1.withLogisticsType(logisticsType);
		
		OrderVo orderVo2 = TradingCallService.createOrderVo();
		
		orderVo2.setOrderItems(Arrays.asList(orderItemVo3));
		
		orderGroupVo.setOrders(Arrays.asList(orderVo1, orderVo2));
		placeOrderReq.setOrderGroups(Arrays.asList(orderGroupVo));

		if (isUserCoupon) {

			CouponVo sellerCoupon1 = TradingAllPromotion.createSellerCouponVo(
					userId, sellerId, new BigDecimal(30), BigDecimal.TEN);

			orderGroupVo.setSellerCoupon(sellerCoupon1);

			CouponVo ymatouCoupon = TradingAllPromotion.createYMTCouponVo(
					userId, new BigDecimal(60), BigDecimal.TEN);
			placeOrderReq.setYmatouCoupon(ymatouCoupon);
		}
		
		placeOrderReq.withUserId(userId).withPayDeductAmount(payDeductAmount);

		return TradingCallService.callPlaceOrderService(placeOrderReq);
	}
	
	/**
	 * 多买手,多商品,生成多个订单
	 * 
	 * @param isUserCoupon
	 * @param canPayDeduct
	 * @param userId
	 * @return
	 */
	public static TradingServiceResp placeOrderWithSixProcutAndFourOrdersInTwoSeller(
			boolean isUserCoupon, BigDecimal payDeductAmount, long userId) {

		PlaceOrderReq placeorderBean = TradingCallService
				.buildStandPlaceOrderReq();

		// 买手1 订单组
		OrderGroupVo orderGroupVo1 = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);

		// 买手1第一个订单
		OrderVo orderVo1 = TradingCallService.createOrderVo();

		// 创建普通商品
		TradingProductVo productVo1 = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		;
		TradingProductVo productVo2 = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		;

		OrderItemVo orderItemVo1 = TradingCallService.createOrderItemVo(
				productVo1.getProductId(), productVo1.getCatalogId());
		OrderItemVo orderItemVo2 = TradingCallService.createOrderItemVo(
				productVo2.getProductId(), productVo2.getCatalogId());

		orderVo1.setOrderItems(Arrays.asList(orderItemVo1, orderItemVo2));

		// 买手1第二个订单
		OrderVo orderVo2 = TradingCallService.createOrderVo();

		TradingProductVo productVo3 = TradingProductVo.createPro(sellerId,
				sellerName, 100);
		;
		OrderItemVo orderItemVo3 = TradingCallService.createOrderItemVo(
				productVo3.getProductId(), productVo3.getCatalogId());

		orderVo2.setOrderItems(Arrays.asList(orderItemVo3));

		orderGroupVo1.setOrders(Arrays.asList(orderVo1, orderVo2));

		if (isUserCoupon) {

			CouponVo sellerCoupon1 = TradingAllPromotion.createSellerCouponVo(
					userId, sellerId, new BigDecimal(30), BigDecimal.TEN);

			orderGroupVo1.setSellerCoupon(sellerCoupon1);

			CouponVo ymatouCoupon = TradingAllPromotion.createYMTCouponVo(
					userId, new BigDecimal(60), BigDecimal.TEN);
			placeorderBean.setYmatouCoupon(ymatouCoupon);
		}

		// 买手2 订单组
		long sellerId2 = Long.valueOf(EnvSetup.getData("SellerId"));

		String sellerName2 = String.valueOf(EnvSetup.getData("SellerName"));

		// 买手2 订单组
		OrderGroupVo orderGroupVo2 = TradingCallService.createOrderGroupVo(
				sellerId, sellerName);

		// 买手2第一个订单
		OrderVo orderVo3 = TradingCallService.createOrderVo();

		TradingProductVo productVo4 = TradingProductVo.createPro(sellerId2,
				sellerName2, 10);
		TradingProductVo productVo5 = TradingProductVo.createPro(sellerId2,
				sellerName2, 10);

		OrderItemVo orderItemVo4 = TradingCallService.createOrderItemVo(
				productVo4.getProductId(), productVo4.getCatalogId());
		OrderItemVo orderItemVo5 = TradingCallService.createOrderItemVo(
				productVo5.getProductId(), productVo5.getCatalogId());

		orderVo3.setOrderItems(Lists.newArrayList(orderItemVo4, orderItemVo5));

		TradingProductVo productVo6 = TradingProductVo.createPro(sellerId2,
				sellerName2, 10);
		OrderItemVo orderItemVo6 = TradingCallService.createOrderItemVo(
				productVo6.getProductId(), productVo6.getCatalogId());

		// 买手2第二个订单
		OrderVo orderVo4 = TradingCallService.createOrderVo();

		orderVo4.setOrderItems(Lists.newArrayList(orderItemVo6));

		orderGroupVo2.setOrders(Lists.newArrayList(orderVo3, orderVo4));

		if (isUserCoupon) {

			CouponVo sellerCoupon2 = TradingAllPromotion.createSellerCouponVo(
					userId, sellerId2, new BigDecimal(30), BigDecimal.TEN);

			orderGroupVo2.setSellerCoupon(sellerCoupon2);
		}

		placeorderBean.setOrderGroups(Arrays.asList(orderGroupVo1));

		placeorderBean.withPayDeductAmount(payDeductAmount).withUserId(userId);

		return TradingCallService.callPlaceOrderService(placeorderBean);
	}
	
	/**
	 * 创建一个砍价团商品订单
	 * 
	 * @param isUserCoupon
	 *            是否使用优惠券（同时使用平台券，商家券）
	 * @param virtualProduct
	 *            是否虚拟商品
	 * @return
	 */
	public static TradingServiceResp placeOrderWithBargainGroup(Boolean isUserCoupon) {

		PlaceOrderReq req = TradingCallService.buildStandPlaceOrderReq();
		
		// 订单信息
		OrderVo orderVo = TradingCallService.createOrderVo();
		
		// 订单商品信息
		List<OrderItemVo> items = new ArrayList<OrderItemVo>();

		// 设置为砍价团订单,不需要交易扣库存，随意设置商品和规格id
		BizVo biz = new BizVo();

		biz.setBizId(TestDataManager.getRandomNum(9));
		biz.setBizSubType(1);
		biz.setBizType(1);

		req.setBizSource(biz);

		// 创建订单项
		OrderItemVo orderItemVo = TradingCallService.createOrderItemVo(TestDataManager
				.getRandomUUID().toString(), TestDataManager.getRandomUUID()
				.toString());

		items.add(orderItemVo);
		
		// 一个商家组
		OrderGroupVo groupVo = TradingCallService.createOrderGroupVo(sellerId,
				sellerName);
		
		if (isUserCoupon) {
			
			// 平台券
			req.setYmatouCoupon(TradingAllPromotion.createYMTCouponVo(
					req.getUserId(), BigDecimal.TEN, BigDecimal.ONE));
			// 商家券
			CouponVo sellerCoupon = TradingAllPromotion.createSellerCouponVo(
					req.getUserId(), sellerId, new BigDecimal(30), BigDecimal.TEN);

			groupVo.setSellerCoupon(sellerCoupon);
		}
		
		// 添加订单
		groupVo.setOrders(Lists.newArrayList(orderVo));
		req.setOrderGroups(Lists.newArrayList(groupVo));
		
		return TradingCallService.callPlaceOrderService(req);
	}
}
